	/**  
* Copyright (c) 2008, Noel Lynch All rights reserved. Redistribution and use  
* in source and binary forms, with or without modification, are permitted  
* provided that the following conditions are met: Redistributions of source  
* code must retain the above copyright notice, this list of conditions and the  
* following disclaimer. Redistributions in binary form must reproduce the above  
* copyright notice, this list of conditions and the following disclaimer in the  
* documentation and/or other materials provided with the distribution. Neither  
* the name of Noel Lynch nor the names of contributors may be used to  
* endorse or promote products derived from this software without specific prior  
* written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT  
* NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A  
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR  
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,  
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,  
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;  
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,  
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR  
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF  
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.  
*/
// Jul 31, 2008

package com.sceneworker.app;

import com.acarter.scenemonitor.SceneMonitor;
import com.jme.input.KeyBindingManager;
import com.jme.input.KeyInput;
import com.jme.input.MouseInput;
import com.jme.math.Vector3f;
import com.jme.renderer.ColorRGBA;
import com.jme.renderer.pass.RenderPass;
import com.jme.scene.Text;
import com.jme2utils.staticutils.GenericJMEUtils;
import com.sceneworker.SceneWorker;

/**
 * Simple Application that can be used to do basic editing on scene elements.
 * @author noellynch
 *
 */
public class SceneWorkerAppMain extends SceneWorkerSimplePassGame {

	public SceneWorkerAppMain() {
	}
	
	@Override
	protected void simpleInitGame() {
		display.getRenderer().setBackgroundColor(new ColorRGBA(0.75f, 0.75f, 0.75f, 1f));
		
		// don't use any default keys
		//KeyBindingManager.getKeyBindingManager().removeAll();
		
		// create a render pass for the root node to be rendered
		RenderPass		lcl_pass = new RenderPass();
		lcl_pass.add(rootNode);
		pManager.add(lcl_pass);
		
		// add a simple grid
		rootNode.attachChild(GenericJMEUtils.buildASimpleGrid(2000, 2000, 100));
		
		// initialise scene worker
		initialiseSceneWorker();
		
		// set camera
		cam.getLocation().set(0f, 10f, 70f);
		cam.lookAt(new Vector3f(0, 0, 0), Vector3f.UNIT_Y);
		
		rootNode.updateRenderState();
		rootNode.updateGeometricState(0, true);
		
		cam.setFrustumFar(10000);
		cam.update();
		
		KeyBindingManager.getKeyBindingManager().add("EnableSceneWorker", KeyInput.KEY_1);
		
		SceneWorker.inst().setToolsEnabled(true);
		input.setEnabled(false);
		MouseInput.get().setCursorVisible(true);
		
	}
	
	public	void	initialiseSceneWorker() {
		// initialise the scene worker and monitor
		// this will give us an inspector and a tree view of the scene graph, pass manager and keybinding manager
		SceneWorker.inst().initialiseSceneWorkerAndMonitor();
		SceneMonitor.getMonitor().registerNode(rootNode, "root");
		SceneMonitor.getMonitor().registerNode(pManager, "Pass Manager");
		SceneMonitor.getMonitor().registerNode(KeyBindingManager.getKeyBindingManager(), "Key Binding Manager");
		
		// initialise the application handler so we get tools palette, input handler and rendering
		SceneWorker.inst().initialiseSceneWorkerTools(rootNode);
	}
	
	@Override
	protected void simpleRender() {
		SceneWorker.inst().render();
	}
	
	@Override
	protected	void	simpleUpdate() {
		if(KeyBindingManager.getKeyBindingManager().isValidCommand("EnableSceneWorker", false)) {
			SceneWorker.inst().setToolsEnabled(!SceneWorker.inst().areToolsEnabled());
			
			if(SceneWorker.inst().areToolsEnabled()) {
				input.setEnabled(false);
				MouseInput.get().setCursorVisible(true);
			} else {
				input.setEnabled(true);
				MouseInput.get().setCursorVisible(false);
			}
		}
		SceneWorker.inst().update(tpf);
	}
		
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		
		SceneWorkerAppMain		lcl_main = new SceneWorkerAppMain();
		lcl_main.setConfigShowMode(ConfigShowMode.ShowIfNoConfig);
		lcl_main.start();
	}

}
